package com.hello.booksale.configuration;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class QiniuConfiguration {
    @Resource
    private QiniuProperties qiniuProperties;
    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(qiniuConfig());
    }
    @Bean
    public com.qiniu.storage.Configuration qiniuConfig() {
        com.qiniu.storage.Configuration cfg=new com.qiniu.storage.Configuration(Region.region1());
        cfg.resumableUploadAPIVersion = com.qiniu.storage.Configuration.ResumableUploadAPIVersion.V2;
        cfg.useHttpsDomains = false;
        return  cfg;
    }
    @Bean
    public Auth auth() {
        return Auth.create(qiniuProperties.getAccessKey(), qiniuProperties.getSecretKey());
    }
    @Bean
    public BucketManager bucketManager(){
        return new BucketManager(auth(),qiniuConfig());
    }



}
